/**
 * Created by sakuri on 2017/4/12
 */
;-function (window) {
    "use strict";
    //预设变量写这里，全局变量写在base.js 里面 使用 r. 调用
    var ready = {
        right_chart_tab_1: null,
        right_chart_tab_2: null,
        index_court: null,
        judge: [],
        judge_name: [],
        dept: [],
        dept_name: [],
        now_judge: [],
        now_judge_name: [],
        courtrooms: [],
        courtrooms_name: [],
        init_date:null,
        status_value:0,//记录当前选择的左侧标签
        count_start_time:null,//记录案件查询时查询总数的时间段
        count_end_time:null,
        right_chart_tab_width:null,
        right_chart_tab_height:null
    };
    //初始化的方法写这里面
    var init = function () {
        Class.draw();//绘制页面
        init_ready();//加载预设变量
        Class.select_all_group();
        Class.select_dept_group();//初始化左侧列表数据
        init_event();
        function init_event() {//初始化页面事件
        	 //时间插件预设为今年
		    $('#startTime').datetimepicker({
		        bootcssVer: 3,
		        minView: "month", //选择日期后，不会再跳转去选择时分秒
		        weekStart: "1",
		        format: "yyyy-mm-dd", //选择日期后，文本框显示的日期格式
		        language: 'zh-CN', //汉化
		        autoclose: true //选择日期后自动关闭
		    }).on('changeDate', function (ev) {
		        console.log(ev.date.valueOf());
		    });
		    $('#endTime').datetimepicker({
		        bootcssVer: 3,
		        minView: "month", //选择日期后，不会再跳转去选择时分秒
		        weekStart: "1",
		        format: "yyyy-mm-dd", //选择日期后，文本框显示的日期格式
		        language: 'zh-CN', //汉化
		        autoclose: true //选择日期后自动关闭
		    }).on('changeDate', function (ev) {
		        console.log(ev.date.valueOf());
		    });
		    $("#endTime").find("input").val(utils.get_date(0));
		    $("#startTime").find("input").val(new Date().getFullYear()+"-01-01");
            Class.init_verify_count();
		    $("#submitButton").click(function(){
	    		Class.init_judge_count();
	    	});
            $('#right_chart_tab_2_li').click(function () {
                console.log(  ready.right_chart_tab_width, ready.right_chart_tab_height);
                var opt = {
                    width: ready.right_chart_tab_width,
                    height: ready.right_chart_tab_height,
                    silent: false
                };
                ready.right_chart_tab_2.resize(opt);
            });
            $('.group-title-user-name').find('span').eq(1).html(r.user_name);
            var court = base.get_court(r.court_id);
            $('.group-title-user-court').find('span').eq(1).html(court.shortname);

            // var vlc = getVLC("vlc");
            // if (vlc) {
            //     vlc.playlist.add(r.base_path+'assets/1212.mp4');
            //     vlc.playlist.play();
            //     vlc.audio.volume = 100
            //     var play = $('.audioplayer-playpause').find('a');
            //     console.log(play.html());
            //     if(play.html()=='Play'){
            //         play.click();
            //     }
            // }

            $(window).resize(function () {
                Class.draw();
            });
            // $('#judge_trial_url').attr('href',r.base_path+'views/judge_trial.html?court='+r.court_id);
        }

        function init_ready() {//初始化预设值
            ready.right_chart_tab_2 = echarts.init(document.getElementById('right-chart-tab-2'), "macarons");
            ready.right_chart_tab_width = $('#right-chart-tab-1').width();
            ready.right_chart_tab_height=$('#right-chart-tab-1').height();
        }
    };
    //内部调用的方法写这里
    var Class = {
        draw: function () {
            //随着窗口大小改变 动态计算布局
            //设置第一块高度
            var window_height = $(window).height();
            var index_left_height = window_height - 325;
            $('#cmp-left-tabs-content').css('height', index_left_height + 'px');
            //设置第一块内元素边距
            var left_tab = ['left-tab-1', 'left-tab-2', 'left-tab-3'];
            $(left_tab).each(function (index, tab_id) {
                var tab = $('#' + tab_id);
                var tabs_li = tab.find('.media-list li');//获取所有条目
                var tabs_li_height = (index_left_height - 44) / 5;//计算每条所占大小
                if (tabs_li_height > 180) {//实际高度不能超过 180
                    tabs_li_height = 180;
                }
                tabs_li.css('height', tabs_li_height + 'px');//设置条目高度
                tabs_li.find('.cmp-left-media-item').css('margin-top', ((tabs_li_height - 30 - 100 ) / 2) + 'px');//每条目所占高度减去实际高度 等于边距高度
            });
            $('.media-list-with-divider').css('height', index_left_height - 40 + 'px');

            var left_img_width = $('.cmp-left-media-item img').actual('width');
            if (left_img_width >= 215) {
                var left_item_width = $('.cmp-left-media-item').actual('width');
                $('.cmp-left-media-item-content').css('width', left_item_width - 263 + 'px');
            }
            //设置第二块高度
            var index_center_height = window_height - 748;
            var cmp_center_panel = $('#cmp-center-tabs-content');
            cmp_center_panel.css('height', index_center_height + 'px');
            //设置第三块高度
            var index_right_height = window_height - 226;
            $('#cmp-right').css('height', index_right_height + 'px');
            ready.right_chart_tab_width = $('#right-chart-tab-1').width();
            ready.right_chart_tab_height=$('#right-chart-tab-1').height();
        },
        select_dept_group: function () {
            $.get(r.base_path + 'archives/selectArchivesInfo', {
                courtId: r.court_id
            }, function (result) {
                if (result && result.status == 0) {
                	ready.init_data = result.data;

                    var dropmenu_judge = $('#dropmenu_judge').find('ul').empty();
                    dropmenu_judge.append('<li><a href="javascript:;" onclick="p.judge_change(\'sometimes_everything_is_ok\')">所有法官</a></li>');
                    var dropmenu_courtroom = $('#dropmenu_courtroom').find('ul').empty();
                    dropmenu_courtroom.append('<li><a href="javascript:;" onclick="p.courtroom_change(\'do_anything_you_want_to_do\')">所有法庭</a></li>');
                    if (result.data && result.data.dept) {
                    	
                        $.each(result.data.dept, function (index, dept) {
                        	dropmenu_judge.append('<li><a href="javascript:;" onclick="p.judge_change(\'' + dept.userId + '\')">' + dept.username + '</a></li>');
                            ready.judge.push(dept.userId);
                            ready.judge_name.push(dept.username);
                            ready.now_judge.push(dept.userId);
                            ready.now_judge_name.push(dept.username);
                        	// if(dept.deptId && ready.dept.indexOf(dept.deptId)==-1){
                        	// 	ready.dept.push(dept.deptId);
                        	// 	ready.dept_name.push(dept.deptname);
                        	// 	dropmenu_dept.append('<li><a href="javascript:;" onclick="p.dept_change(\'' + dept.deptId + '\')">' + dept.deptname + '</a></li>');
                        	// }
                        })
                    } else {
                        $('#dropmenu_dept').find('a').eq(0).html('无部门');
                        $('#dropmenu_judge').find('a').eq(0).html('无法官');
                    }
                    if (result.data && result.data.courtroom) {
                        $.each(result.data.courtroom, function (index, courtroom) {
                            dropmenu_courtroom.append('<li><a href="javascript:;" onclick="p.courtroom_change(\'' + courtroom.uid + '\')">' + courtroom.courtroomname + '</a></li>');
                            ready.courtrooms.push(courtroom.uid);
                            ready.courtrooms_name.push(courtroom.courtroomname);
                        })
                    } else {
                        $('#dropmenu_courtroom').find('a').eq(0).html('无法庭');
                    }
                    if (ready.judge.length > 0 && ready.courtrooms.length > 0) {
                        Class.init_case_today(ready.judge, null);
 	                    Class.init_total();//初始化顶部统计栏
                        Class.init_judge_count();//初始化顶部统计栏
                        Class.init_count_time();
                        Class.init_judge_ranking();
                        Class.init_verify_count();
                    } else {
                        layui.use('layer', function () {
                            layui.layer.msg("没有相关数据,请先配置管理的法官!");
                        });
                    }

                }
            }, 'json');
        },
        select_all_group: function(){
            $.get(r.base_path + 'archives/selectAllDepartment', {
                courtId: r.court_id
            }, function (result) {
                var dropmenu_dept = $('#dropmenu_dept').find('ul').empty();
                dropmenu_dept.append('<li><a href="javascript:;" onclick="p.dept_change(\'sometimes_everything_is_ok\')">所有部门</a></li>');
                if (result.data) {
                    $.each(result.data, function (index, dept) {
                            ready.dept.push(dept.uid);
                            ready.dept_name.push(dept.deptname);
                        dropmenu_dept.append('<li><a href="javascript:;" onclick="p.dept_change(\'' + dept.uid + '\')">' + dept.deptname + '</a></li>');

                    })
                } else {
                    $('#dropmenu_dept').find('a').eq(0).html('无部门');
                    $('#dropmenu_judge').find('a').eq(0).html('无法官');
                }

            },'json');
        },
        init_total: function () {//TODO 顶部栏需要修改
            var anime = show_anime(50);
            $.get(r.base_path + 'selectStatisticalByCourtId', {
                courtId: r.court_id
            }, function (result) {
                if (result.status == 0 && result.data) {
                    setTimeout(function () {
                        anime.close();
                        show(result.data);
                    }, 1000);//1秒后加载 后续优化可以去除
                }

            }, 'JSON');

            function show(data) {
                //总容量
                var file_size_total = parseInt(data.fileSizeTotal / 1048576);//这里单位是M 需要转换成T
                var file_size_total_arr = format(file_size_total);
                var cmp_plugins_title_size_span = $('.cmp-plugins-title-size span');
                cmp_plugins_title_size_span.eq(0).html(file_size_total_arr[0]);
                cmp_plugins_title_size_span.eq(1).html(file_size_total_arr[1]);
                cmp_plugins_title_size_span.eq(2).html(file_size_total_arr[2]);
                cmp_plugins_title_size_span.eq(3).html(file_size_total_arr[3]);
                //闭庭数
                var closed_court_total_arr = format(data.closedCourtTotal);
                var cmp_plugins_title_closed_span = $('.cmp-plugins-title-closed span');
                cmp_plugins_title_closed_span.eq(0).html(closed_court_total_arr[0]);
                cmp_plugins_title_closed_span.eq(1).html(closed_court_total_arr[1]);
                cmp_plugins_title_closed_span.eq(2).html(closed_court_total_arr[2]);
                cmp_plugins_title_closed_span.eq(3).html(closed_court_total_arr[3]);
                //开庭数
                var open_court_time_total_arr = format(data.countCourtNowTotal);
                var cmp_plugins_title_open_court = $('.cmp-plugins-title-open-court span');
                cmp_plugins_title_open_court.eq(0).html(open_court_time_total_arr[0]);
                cmp_plugins_title_open_court.eq(1).html(open_court_time_total_arr[1]);
                cmp_plugins_title_open_court.eq(2).html(open_court_time_total_arr[2]);
                cmp_plugins_title_open_court.eq(3).html(open_court_time_total_arr[3]);
                //法庭总数
                var court_room_total_arr = format(data.courtRoomTotal);
                var cmp_plugins_title_court = $('.cmp-plugins-title-court span');
                cmp_plugins_title_court.eq(0).html(court_room_total_arr[0]);
                cmp_plugins_title_court.eq(1).html(court_room_total_arr[1]);
                cmp_plugins_title_court.eq(2).html(court_room_total_arr[2]);
                cmp_plugins_title_court.eq(3).html(court_room_total_arr[3]);
                //科技法庭数
                var technology_court_total_arr = format(data.technologyCourtTotal);
                var cmp_plugins_title_technology = $('.cmp-plugins-title-technology span');
                cmp_plugins_title_technology.eq(0).html(technology_court_total_arr[0]);
                cmp_plugins_title_technology.eq(1).html(technology_court_total_arr[1]);
                cmp_plugins_title_technology.eq(2).html(technology_court_total_arr[2]);
                cmp_plugins_title_technology.eq(3).html(technology_court_total_arr[3]);
                //总时长
                var count_court_now_total_arr = format(Math.round(data.openCourtTimeTotal / 24));
                var cmp_plugins_title_now = $('.cmp-plugins-title-now span');
                cmp_plugins_title_now.eq(0).html(count_court_now_total_arr[0]);
                cmp_plugins_title_now.eq(1).html(count_court_now_total_arr[1]);
                cmp_plugins_title_now.eq(2).html(count_court_now_total_arr[2]);
                cmp_plugins_title_now.eq(3).html(count_court_now_total_arr[3]);
            }

            function show_anime(delaytime) {
                if (!delaytime) {
                    delaytime = 100;
                }
                var anime_it = setInterval(function () {
                    var data = {};
                    data.fileSizeTotal = get_random_arr() * 1024 * 1024;
                    data.closedCourtTotal = get_random_arr();
                    data.openCourtTimeTotal = get_random_arr();
                    data.courtRoomTotal = get_random_arr();
                    data.technologyCourtTotal = get_random_arr();
                    data.countCourtNowTotal = get_random_arr();
                    show(data);
                }, delaytime);
                return {
                    close: function () {
                        clearInterval(anime_it);
                    }
                };
                function get_random_arr() {
                    return Math.floor(Math.random() * 10000);
                }
            }

            /**
             * 将数据拆分，转换成4位字符串数组，不足补0。
             * @param num 需要转换的数据
             * @return [*] 4位字符数组
             */
            function format(num) {
                var result_arr = ['0', '0', '0', '0'];
                if (!num) {
                    return result_arr;
                }
                num = num + '';
                var num_arr = num.split('');
                for (var i = 3, j = 3; i > -1; i--) {
                    if (num_arr[i]) {
                        result_arr[j] = num_arr[i];
                        j--;
                    }
                }
                return result_arr;
            }
        },
	    dept_change: function (dept_uid) {
            console.info(ready.init_data.dept);
	    	console.info(dept_uid);
	     	 ready.now_judge = [];
        	 ready.now_judge_name = [];
        	 var dropmenu_judge = $('#dropmenu_judge').find('ul').empty();
        	 dropmenu_judge.append('<li><a href="javascript:;" onclick="p.judge_change(\'sometimes_everything_is_ok\')">所有法官</a></li>');
        	 $('#dropmenu_judge').find('a').eq(0).html('所有法官 <span class="caret"></span>');
	     	 if (dept_uid=='sometimes_everything_is_ok'){
                $('#dropmenu_dept').find('a').eq(0).html('所有部门 <span class="caret"></span>');
                $.each(ready.init_data.dept, function (index, dept) {
                        	dropmenu_judge.append('<li><a href="javascript:;" onclick="p.judge_change(\'' + dept.userId + '\')">' + dept.username + '</a></li>');
                        	ready.now_judge.push(dept.userId);
                        	ready.now_judge_name.push(dept.username);
                        })
                
            }else {
            	var dept_no = ready.dept.indexOf(dept_uid);
            	$('#dropmenu_dept').find('a').eq(0).html(ready.dept_name[dept_no] + ' <span class="caret"></span>');
		        $.each(ready.init_data.dept, function (index, dept) {
		            if (dept.deptId == dept_uid) {
		                dropmenu_judge.append('<li><a href="javascript:;" onclick="p.judge_change(\'' + dept.userId + '\')">' + dept.username + '</a></li>');
                    	ready.now_judge.push(dept.userId);
                    	ready.now_judge_name.push(dept.username);
		            }
		        });
            }
	        var dropmenu_courtroom = $('#dropmenu_courtroom').find('a').eq(0).html();
	        dropmenu_courtroom = dropmenu_courtroom.replace('<span class="caret"></span>').trim();
	        if (ready.courtrooms_name.indexOf(dropmenu_courtroom)>0){
	            $.each(ready.courtrooms, function (courtroom_no, courtroom) {
	                if (courtroom == dropmenu_courtroom) {
	                    var temp_courtroom = [ready.courtroom[courtroom_no]];
	                    Class.init_case_today(ready.now_judge, temp_courtroom);
	                }
	            });
	        }else {
	            Class.init_case_today(ready.now_judge, ready.courtrooms);
	        }
	
	    },
        judge_change: function (judge_uid) {
            var temp_judge = [judge_uid];
            if (judge_uid=='sometimes_everything_is_ok'){
                $('#dropmenu_judge').find('a').eq(0).html('所有法官 <span class="caret"></span>');
                temp_judge = ready.now_judge;
            }else {
                $.each(ready.judge, function (judge_no, judge) {
                    if (judge == judge_uid) {
                        $('#dropmenu_judge').find('a').eq(0).html(ready.judge_name[judge_no] + ' <span class="caret"></span>');
                    }
                });
            }
            var dropmenu_courtroom = $('#dropmenu_courtroom').find('a').eq(0).html();
            dropmenu_courtroom = dropmenu_courtroom.replace('<span class="caret"></span>','').trim();
            if (ready.courtrooms_name.indexOf(dropmenu_courtroom)>-1){
                $.each(ready.courtrooms, function (courtroom_no, courtroom) {
                    if (courtroom == dropmenu_courtroom) {
                        var temp_courtroom = ready.courtroom[courtroom_no];
                        Class.init_case_today(temp_judge, temp_courtroom);
                    }
                });
            }else {
                Class.init_case_today(temp_judge, ready.courtrooms);
            }

        },
        courtroom_change: function (courtroom_uid) {
            var temp_courtroom = courtroom_uid;
            if (courtroom_uid=='do_anything_you_want_to_do'){
                $('#dropmenu_courtroom').find('a').eq(0).html('所有法庭 <span class="caret"></span>');
//                temp_courtroom = ready.courtrooms;
                temp_courtroom = null ;
            }else {
                $.each(ready.courtrooms, function (courtroom_no, courtroom) {
                    if (courtroom == courtroom_uid) {
                        $('#dropmenu_courtroom').find('a').eq(0).html(ready.courtrooms_name[courtroom_no] + ' <span class="caret"></span>');
                    }
                });
            }
            var judge_name = $('#dropmenu_judge').find('a').eq(0).html();
            judge_name = judge_name.replace('<span class="caret"></span>','').trim();
            if (ready.judge_name.indexOf(judge_name)>-1){
                $.each(ready.judge_name, function (judge_no, judge) {
                    if (judge == judge_name) {
                        var temp_judge = [ready.judge[judge_no]];
                        Class.init_case_today(temp_judge, temp_courtroom);
                    }
                });
            }else {
                Class.init_case_today(ready.now_judge, temp_courtroom);
            }
        },
        init_case_today: function (judge, court_room) {
            judge =judge.toString();
//            court_room = court_room.toString();
            $.post(r.base_path + 'findJudgeCaseScheduleList', {
                courtId: r.court_id,
                // startDate: utils.get_date(0),
                judgeList: judge,
                courtroomId: court_room,
                page: 1,
                pageSize: 5
            }, function (result) {
                $('#left-tab-1').find('.media-list').empty();
                if (result && result.status == 0) {
                    if (result.data == null) {
                        return;
                    }
                    var left_tab_1 = $('#left-tab-1');
                    left_tab_1.find('.media-list').empty();
                    $(result.data).each(function (index, elem) {
                        var startDate = elem.start_date.substring(0, elem.start_date.length - 5);
                        var uri = encodeURI(r.base_path + "views/archives/living.html?uid=" + elem.uid + "&cid=" + elem.courtroom_id + "&city=" + r.court_id + "&court=" + r.court_id + "&vc=" + elem.courtId);
                        left_tab_1.find('.media-list').append('<li class="media media-lg">' +
                            '<a href="' + uri + '"><div class="cmp-left-media-item">' +
                            '<div class="cmp-left-media-item-img">' +
                            '<span class="cmp-left-media-item-status">' + elem.statusName + '</span>' +
                            '<img src="'+r.base_path+'assets/img/list_test2.jpg"/>' +
                            '</div>' +
                            '<div class="cmp-left-media-item-content">' +
                            '<p class="cmp-left-media-item-p cmp-left-media-item-title">' + (elem.casename ? elem.casename : '未知') + '</p>' +
                            '<p class="cmp-left-media-item-p cmp-left-media-item-addr">开庭地点：' + (elem.courtroom_name ? elem.courtroom_name : '未知') + '</p>' +
                            '<p class="cmp-left-media-item-p">' +
                            '<span class="cmp-left-media-item-type">' + (elem.casetype_name ? elem.casetype_name : '未知') + '</span>' +
                            '<span class="cmp-left-media-item-time"><i class="fa fa-clock-o"></i>' + startDate + '</span>' +
                            '</p>' +
                            '</div>' +
                            '</div></a>' +
                            '</li>');
                    });
                    left_tab_1.find('.cmp-left-tabs-link a').attr('href', r.base_path + 'views/archives/more_courting.html');
                    Class.draw();
                }
            }, 'json');
            $.post(r.base_path + 'findJudgeCaseReviewList', {
                courtId: r.court_id,
                judgeList: judge,
                courtroomId: court_room,
                start: 0,
                pageSize: 5
            }, function (result) {
                var left_tab_2 = $('#left-tab-2');
                left_tab_2.find('.media-list').empty();
                if (result && result.status == 0) {
                    if (result.data == null) {
                        console.log('无开庭')
                    }
                }
                $(result.data).each(function (index, elem) {
                    var startDate = elem.start_date.substring(0, elem.start_date.length - 2);
                    var uri = encodeURI(r.base_path + "views/archives/play.html?planId=" + elem.uid + "&city=" + r.court_id + "&court=" + r.court_id + "&vc=" + elem.courtId);
                    left_tab_2.find('.media-list').append('<li class="media media-lg">' +
                        '<a href="' + uri + '"><div class="cmp-left-media-item">' +
                        '<div class="cmp-left-media-item-img">' +
                        '<img src="'+r.base_path+'assets/img/list_test2.jpg"/>' +
                        '</div>' +
                        '<div class="cmp-left-media-item-content">' +
                        '<p class="cmp-left-media-item-p cmp-left-media-item-title">' + (elem.casename ? elem.casename : '未知') + '</p>' +
                        '<p class="cmp-left-media-item-p cmp-left-media-item-addr">开庭地点：' + (elem.courtroom_name ? elem.courtroom_name : '未知') + '</p>' +
                        '<p class="cmp-left-media-item-p">' +
                        '<span class="cmp-left-media-item-type">' + (elem.casetype_name ? elem.casetype_name : '未知') + '</span>' +
                        '<span class="cmp-left-media-item-time"><i class="fa fa-clock-o"></i>' + startDate + '</span>' +
                        '</p>' +
                        '</div>' +
                        '</div></a>' +
                        '</li>');
                });
                left_tab_2.find('.cmp-left-tabs-link a').attr('href', r.base_path + "views/archives/more_reviewing.html?court=" + r.court_id);
                Class.draw();
            }, 'json').fail(function () {

            });
        },
        init_judge_count: function () {
        	//获取时间
        	var end_time = $("#endTime").find("input").val();
		    var start_time = $("#startTime").find("input").val();
		    ready.count_start_time = start_time;
		    ready.count_end_time = end_time;
		    //获取案号
		    var case_no = $("#caseno").val();
		    //获取当前选择的法官
		    var temp_judge = [];
		    var selected_judge_name = $("#dropmenu_judge a:first").html().replace('<span class="caret"></span>','').trim();
			if (ready.judge_name.indexOf(selected_judge_name)>-1){
                $.each(ready.judge_name, function (judge_no, judge) {
                    if (judge == selected_judge_name) {
                        temp_judge.push(ready.judge[judge_no]);
                    }
                });
            }else {
                temp_judge = ready.now_judge;
            }
            //获取当前法庭Id
            var temp_courtroom = null;
            var selected_courtroom_name = $("#dropmenu_courtroom a:first").html().replace('<span class="caret"></span>','').trim();
			if (ready.courtrooms_name.indexOf(selected_courtroom_name)>-1){
                $.each(ready.courtrooms_name, function (courtroom_no, courtroom) {
                    if (courtroom == selected_courtroom_name) {
                        temp_courtroom = ready.courtrooms[courtroom_no];
                    }
                });
            }
            //获取当前是排期或者回顾
            var status_tab = $(".cmp-left-tabs").find(".active").find("a").html();
            if("庭审排期" == status_tab){
            	ready.status_value = "0";
            }else if("庭审回顾" == status_tab){
            	ready.status_value = "1";
            }else{
            	ready.status_value = "2";
            }

            if(ready.status_value == "2"){
            	$("#right-list-tab-1").html("");
            	$("#right-list-tab-1").append('<span>暂无数据</span>')
            }else{
            	 $.get(r.base_path + 'findListJudgeScheduleOrReviewCountCase', {
			    	judgeList:temp_judge.toString(),
	                courtId: r.court_id,
	                courtRoomId:temp_courtroom,
	                startDate:start_time,
	                endDate:end_time,
	                caseno:case_no,
	                status:ready.status_value
	            }, function (result) {
	            	if(result.status == 1){
	            		$("#right-list-tab-1").html("");
            			$("#right-list-tab-1").append('<span>无数据</span>');
            			return;
	            	}
	            	$("#right-list-tab-1").html("");
	            	
                    $("#right-list-tab-1").append('<table id="table" class="table table-bordered context-span context-white cursor-hand"></table>');
            		$("#right-list-tab-1").append('<div id="_page"></div>');
	            	
	             	var sum = result.data;
	             	if (sum == 0) {
		                page(1, 1, null);
		            } else {
		                page(1, Math.ceil(sum / 5), Class.init_judge_detail);
		            }
	            	Class.init_judge_detail(1);
	            }, 'json').fail(function () {
					 alert("查询失败");
	            });
            }
		   
        },
        init_judge_detail: function (Index) {
        	//获取时间
        	var end_time = ready.count_end_time;
		    var start_time = ready.count_start_time;
		    //获取案号
		    var case_no = $("#caseno").val();
		    //获取当前选择的法官
		    var temp_judge = [];
		    var selected_judge_name = $("#dropmenu_judge a:first").html().replace('<span class="caret"></span>','').trim();
			if (ready.judge_name.indexOf(selected_judge_name)>-1){
                $.each(ready.judge_name, function (judge_no, judge) {
                    if (judge == selected_judge_name) {
                        temp_judge.push(ready.judge[judge_no]);
                    }
                });
            }else {
                temp_judge = ready.now_judge;
            }
            //获取当前法庭Id
            var temp_courtroom = null;
            var selected_courtroom_name = $("#dropmenu_courtroom a:first").html().replace('<span class="caret"></span>','').trim();
			if (ready.courtrooms_name.indexOf(selected_courtroom_name)>-1){
                $.each(ready.courtrooms_name, function (courtroom_no, courtroom) {
                    if (courtroom == selected_courtroom_name) {
                        temp_courtroom = ready.courtrooms[courtroom_no];
                    }
                });
            }
            
            if(ready.status_value == "2"){
            	$("#right-list-tab-1").html("");
            	$("#right-list-tab-1").append('<span>暂无数据</span>')
            }else{
            	 $.get(r.base_path + 'findListJudgeScheduleOrReviewCase', {
			    	judgeList:temp_judge.toString(),
	                courtId: r.court_id,
	                courtRoomId:temp_courtroom,
	                startDate:start_time,
	                endDate:end_time,
	                caseno:case_no,
	                status:ready.status_value,
	                page:Index,
	                pageSize:5
	            }, function (result) {
	            	$('#table').bootstrapTable({
//			    	paginationLoop:true,
			        columns: [{
			            field: 'courtroom_name',
			            title: '法庭'
			        }, {
			            field: 'judge_id',
			            title: '法官',
			            formatter: function (value, row, index) {
			                if (ready.judge.indexOf(value)>-1){
			                	return ready.judge_name[ready.judge.indexOf(value)]
				            }else{
				            	 return "-";
				            }
				           
			            }
			        },{
			            field: 'caseno',
			            title: '案件号'
			        }, {
			             field: 'casename',
			             title: '案件名称'
			        },{
			             field: 'summary',
			             title: '概要'
			        },{
			             field: 'start_date',
			             title: '开庭时间'
			        }
			           ],
			        data: result.data,
			        onClickRow:function (row) {
			        	console.info(row.plan_id);
			        	Class.getCaseInfoById(row.plan_id);
			        	Class.getCourtrecForId(row.plan_id);
			        	if(row.status>2){
			        		Class.getInfo(row.plan_id);
			        	}else{
			        		var court_ip = currentServerIP();
//			        		Class.get_living_channel(row.plan_id,row.courtroom_id,court_ip);
			        		getCgf(row.plan_id,row.courtroom_id,court_ip);
			        	}
			        	
			        	
			        }
			    });
	            $('#table').bootstrapTable("load",result.data);
	            $('#table').bootstrapTable("hideLoading");	
	            	
	            }, 'json').fail(function () {
					 alert("查询失败");
	            });
            }
		   
        },
        init_verify_count:function () {
            var judge_list = [];
            var judge_name = $('#dropmenu_judge').find('a').eq(0).html();
            judge_name = judge_name.replace('<span class="caret"></span>', '').trim();
            if (ready.judge_name.indexOf(judge_name) > -1) {
                $.each(ready.judge_name, function (judge_no, judge) {
                    if (judge == judge_name) {
                        judge_list = [ready.judge[judge_no]];
                    }
                });
            }else {
                judge_list = ready.judge;
            }
            var end_time = $("#endTime").find("input").val();
            var start_time = $("#startTime").find("input").val();
            $.get(r.base_path + 'major/findAllImagesCount', {
                courtId: r.court_id,
                userIds:JSON.stringify(judge_list),
                start:start_time,
                end:end_time,
                type:0
            }, function (result) {
                if(result.status == 1){
                    $("#right-list-tab-2").html("");
                    $("#right-list-tab-2").append('<span>无数据</span>');
                    return;
                }
                $("#right-list-tab-2").html("");

                $("#right-list-tab-2").append('<table id="table2" class="table table-bordered context-span context-white cursor-hand"></table>');
                $("#right-list-tab-2").append('<div id="_page2"></div>');

                var sum = result.data;
                if (sum == 0) {
                    page2(1, 1, null);
                } else {
                    page2(1, Math.ceil(sum / 5), Class.init_verify_page);
                }
                Class.init_verify_page(1);
            }, 'json').fail(function () {
                alert("查询失败");
            });
        },
        init_verify_page:function (page) {
            var judge_list = [];
            var judge_name = $('#dropmenu_judge').find('a').eq(0).html();
            judge_name = judge_name.replace('<span class="caret"></span>', '').trim();
            if (ready.judge_name.indexOf(judge_name) > -1) {
                $.each(ready.judge_name, function (judge_no, judge) {
                    if (judge == judge_name) {
                        judge_list = [ready.judge[judge_no]];
                    }
                });
            }else {
                judge_list = ready.judge;
            }
            var end_time = $("#endTime").find("input").val();
            var start_time = $("#startTime").find("input").val();
            $.get(r.base_path + 'major/findAllImages', {
                courtId: r.court_id,
                userIds:JSON.stringify(judge_list),
                start:start_time,
                end:end_time,
                page:page,
                pageSize:5,
                type:0
            }, function (result) {
                $('#table2').bootstrapTable({
//			    	paginationLoop:true,
                    columns: [{
                        field: 'create_user',
                        title: '创建人'
                    },{
                        field: 'name',
                        title: '图片名称',
                        formatter: function (result,row) {
                            var date=new Date(row.create_time);
                            var type=row.type;
                            var url="http://"+location.hostname+":8080/";
                            if(type==1){
                                //图片
                                url=url+"images/";
                            }else{
                                //视频
                                url=url+"videos/";
                            }
                            url=url+date.getFullYear()+"/"+(date.getMonth() + 1)+"/"+result;
                            //拼接下载地址
                            var a="<a download class='btn btn-primary' href='"+url+"'>"+result+"</a>";
                            return a;
                        }
                    }, {
                        field: 'casename',
                        title: '案件名称'
                    },{
                        field: 'channelsame',
                        title: '通道名称'
                    },{
                        field: 'start_time',
                        title: '截取起点'
                    },{
                        field: 'end_time',
                        title: '截取终点'
                    },{
                        field: 'type',
                        title: '类型',
                        formatter: function (value) {
                            if (value==1){
                                return '图片'
                            }else if (value==2){
                                return '视频';
                            }else {
                                return '未知';
                            }

                        }
                    }],
                    data: result.data,
                    onClickRow:function (row) {
                    }
                });
                $('#table2').bootstrapTable("load",result.data);
                $('#table2').bootstrapTable("hideLoading");
            }, 'json').fail(function () {
                alert("查询失败");
            });
        },
        init_count_time:function(){
        	//获得时间月份数组
        	var now = new Date();
        	var month = now.getMonth()+1;
        	var start_time = null;
        	if(month >= 7){
        		var start_month = month-6;
        		start_time = now.getFullYear()+"-0"+start_month;
        	}else{
        		var start_month = 12+month-6;
        		if (start_month < 10) {
	        		start_time = now.getFullYear()-1+"-0"+start_month;
	        	}else {
	        		start_time = now.getFullYear()-1+"-"+start_month;
	        	}
        	}
        	if (month < 10) {
        		month = "0"+month;
        	}
        	var end_time = now.getFullYear()+"-"+month;
        	var time_arr = [start_time];
        	for(var i=0;i<5;i++){
        		var last_month = parseInt(time_arr[time_arr.length-1].substr(5));
        		if(last_month<12){
        			var temp_month = last_month+1;
        			if(temp_month<10){
        				time_arr.push(time_arr[time_arr.length-1].substr(0,4)+"-0"+temp_month);
        			}else{
        				time_arr.push(time_arr[time_arr.length-1].substr(0,4)+"-"+temp_month);
        			}
        		}else if(last_month == 12){
        			time_arr.push(parseInt(time_arr[time_arr.length-1].substr(0,4))+1+"-01");
        		}
        	}
        	time_arr.push(end_time);
//        	console.info(time_arr);
        	 $.get(r.base_path + 'findListJudgeMonthStatistics', {
			    	startDate:start_time,
	                endDate: end_time,
	                judgeList:ready.judge.toString()
	            }, function (result) {

	            	var ydata = [];
	            	for(var i=0;i<time_arr.length;i++){
	            		ydata[i] = 0 ;
	            		$.each(result.data,function(index,elem){
	            			if(time_arr[i] == elem.date){
	            				ydata[i] = elem.trialtime ;
	            			}
	            		});
	            	}

	            	 var myChart = echarts.init(document.getElementById('right-chart-tab-1'), "shine");
				    // 指定图表的配置项和数据
				    var option = {
//				    		title: {
//				    			text: "开庭数统计(次)", //正标题
//				    			x: "left", //标题水平方向位置
//				    			textStyle: {
//				    				fontSize:24,
//				    				color:"#FFFFFF"
//				    				}
//				    		},
				        color: ['#D5B136'],
				       /* title:{
				          text:title,
				            textStyle:{
				              color:"#ffffff"
				            }
				        },*/
				        grid: {
                            show: false,
                            left: '9%',
                            right: '6%',
                            top: 30,
                            bottom: 30
						},
				        tooltip: {},
				        xAxis: {
				            data: time_arr,
				            axisLine: {
				                lineStyle: {
				                    color: "#1c4e93"
				                }
				            },
				            axisLabel: {
				                textStyle: {
				                	fontSize:16,
				                    color: "#FFFFFF"
				                },
					           // rotate:-30,
					            interval:0
				            }
				        },
				        yAxis: {
				            axisLine: {
				                lineStyle: {
				                    color: "#1c4e93"
				                }
				            },
				            axisLabel: {
				                textStyle: {
				                	fontSize:16,
				                    color: "#FFFFFF"
				                },
				                formatter: function (value) {
				                                return value + 'h'
				                            }
				            }
				        },
				        series: [{
				            name: '开庭时长',
				//            barWidth: '50%',
				            barMaxWidth:20,
				            type: 'bar',
				            itemStyle:{
				            	normal:{
				            		label:{
				            			show:true,
				            			position:'top',
				            			textStyle: {
				                            color: "#d94600",
				                            fontSize:20
				                        }
				            		}
				            	}
				            },
				            data: ydata
				        }]
				    };
				    // 使用刚指定的配置项和数据显示图表。
				    myChart.setOption(option);
				    window.onresize = myChart.resize;

	            }, 'json').fail(function () {
					 alert("查询失败");
	            });

        },
		init_judge_ranking:function(){
			var now = new Date();
        	var month = now.getMonth()+1;
        	var start_time = null;
        	if(month >= 7){
        		var start_month = month-6;
        		start_time = now.getFullYear()+"-0"+start_month;
        	}else{
        		var start_month = 12+month-6;
        		if (start_month < 10) {
	        		start_time = now.getFullYear()-1+"-0"+start_month;
	        	}else {
	        		start_time = now.getFullYear()-1+"-"+start_month;
	        	}
        	}
        	if (month < 10) {
        		month = "0"+month;
        	}
        	var end_time = now.getFullYear()+"-"+month;
        	$.get(r.base_path + 'listJudgeRankingStatistics', {
			    	startDate:start_time,
	                endDate: end_time,
	                judgeList:ready.judge.toString()
	            }, function (result) {

	            	var sum_judge = [];
		            var sum_max = 1;
		            $(result.data).each(function (i, elem) {
		                elem.trialtime>sum_max?sum_max = elem.trialtime:'';
		                var judge = [];
		                judge.push(elem.trialnum);
		                judge.push(elem.trialtime);
		                judge.push(elem.username);
		                sum_judge.push(judge);
		                // users.push(n.username);
		                // counts.push(n.sum);
		                // nums.push(n.timelong);
		            });
//		            console.info(sum_judge,">>>>",sum_max);
		//            sum_judge_echart(sum_judge,sum_max);

				    var option = {
				        grid: [{
				            show: false,
				            left: '9%',
				            right: '6%',
				            top: 30,
				            bottom: 30
				        }],
				        tooltip: {
				            padding: 10,
				            backgroundColor: '#222',
				            borderColor: '#777',
				            borderWidth: 1,
				            formatter: function (obj) {
				                var value = obj.value;
				                return '<div style="border-bottom: 1px solid rgba(255,255,255,.3); font-size: 18px;padding-bottom: 7px;margin-bottom: 7px">' +
				                    '姓名：' + value[2] +
				                    '</div>' +
				                    '开庭次数：' + value[0] + '次<br>' +
				                    '开庭时长：' + value[1] + '小时<br>';
				            }
				        },
				        xAxis: {
				            splitLine: {
				                show: false
				            },
				            axisLine: {
				                lineStyle: {
				                    color: '#fff'
				                }
				            },
				            axisLabel:{
				                formatter: function (value) {
				                    return value + '次'
				                }
				            }
				        },
				        yAxis: {
				            nameTextStyle: {
				                color: '#fff',
				                fontSize: 16
				            },
				            splitNumber:4,
				            axisLine: {
				                lineStyle: {
				                    color: '#eee',
				                    show: false
				                }
				            },
				            axisLabel:{
				                formatter: function (value) {
				                    return value + 'h'
				                }
				            },
				            splitLine: {
				                show: false
				            },
				            scale: true
				        },

				        series: [{
				            name: '开庭次数',
				            data: sum_judge,
				            type: 'scatter',
				            symbolSize: function (data) {
				                return (data[1]/sum_max)*25+10;
				            },
				            label: {
				                emphasis: {
				                    show: true,
				                    formatter: function (param) {
				                        return param.data[2];
				                    },
				                    position: 'top'
				                }
				            },
				            itemStyle: {
				                normal: {
				                    color: '#009999'
				                }
				            }
				        }]
				    };
                ready.right_chart_tab_2.setOption(option);
                window.onresize = ready.right_chart_tab_2.resize;

	            }, 'json').fail(function () {
					 alert("查询失败");
	            });
		},
		getCaseInfoById:function(uid) {
		    $.ajax({
		        url: r.base_path + "getCaseInfoByUid",
		        type: "post",
		        dataType: "json",
		        data: {
		            uid: uid,
		            courtId: r.court_id
		        },
		        success: function (result) {
		            if(result.status==1){
		                return ;
		            }
		            var caseInfo = result.data;
		            var caseNo = caseInfo.caseno;
		            var caseName = caseInfo.casename;
		            var subName = "";
		            var caseTypeName = caseInfo.casetype_name;
		            var judgeName = caseInfo.judge_id;
		            var secretaryName = caseInfo.secretary_id;
		            var courtroomName = caseInfo.courtroom_name;
		            var statusName = caseInfo.statusName;
		            var parties = caseInfo.accuse + " " + caseInfo.accused;
		            var startDate = caseInfo.start_date;
		            startDate = startDate.substring(0, startDate.length - 2);
		
		            var endDate = '未知';
		            if(caseInfo.end_date){
		                endDate = caseInfo.end_date.substring(0, caseInfo.end_date.length - 2);
		            }
		            var caseDesc = caseInfo.casedesc;
		            if (caseDesc == null) {
		                caseDesc = "";
		            }
//		            console.log(result);
//		            $("#title").html('&nbsp;' + caseNo + "——" + caseName);
		            var html = ['  <div class="cmp-play-text">',
		                '                        <div class="row row-court">',
		                '                            <div class="col-md-3 col-xs-4 text-right">',
		                '                                <span> 案  号：</span>',
		                '                            </div>',
		                '                            <div class="col-md-9 col-xs-8 text-left">',
		                '                                <span>' + caseNo + '</span>',
		                '                            </div>',
		                '                        </div>',
		                '                        <div class="row row-court">',
		                '                            <div class="col-md-3 col-xs-4 text-right">',
		                '                                <span>案件类型：</span>',
		                '                            </div>',
		                '                            <div class="col-md-3 col-xs-8 text-left">',
		                '                                <span>' + caseTypeName + '</span>',
		                '                            </div>',
		                '                        </div>',
		                '                        <div class="row row-court">',
		                '                            <div class="col-md-3 col-xs-4 text-right">',
		                '                                <span>案件名称：</span>',
		                '                            </div>',
		                '                            <div class="col-md-9 col-xs-8 text-left">',
		                '                                <span>' + caseName + '</span>',
		                '                            </div>',
		                '                        </div>',
		                '                        <div class="row row-court">',
		                '                            <div class="col-md-3 col-xs-4 text-right">',
		                '                                <span> 审判长：</span>',
		                '                            </div>',
		                '                            <div class="col-md-3  col-xs-8 text-left">',
		                '                                <span><a id="judge_name" class="white-a">' + (caseInfo.judge_name ? caseInfo.judge_name : '未知') + '</a></span>',
		                '                            </div>',
		                '                            <div class="col-md-3 col-xs-4 text-right">',
		                '                            </div>',
		                '                            <div class="col-md-3  col-xs-8 text-left">',
		                '                            </div>',
		                '                            <div class="col-md-3 col-xs-4 text-right">',
		                '                                <span> 书记员：</span>',
		                '                            </div>',
		                '                            <div class="col-md-3  col-xs-8 text-left">',
		                '                                <span>' + (caseInfo.secretary_name ? caseInfo.secretary_name : '未知') + '</span>',
		                '                            </div>',
		                '                        </div>',
		                '                        <div class="row row-court">',
		                '                            <div class="col-md-3 col-xs-4 text-right">',
		                '                                <span>当事人：</span>',
		                '                            </div>',
		                '                            <div class="col-md-9 col-xs-8 text-left">',
		                '                                <span>' + parties + '</span>',
		                '                            </div>',
		                '                        </div>',
		                '                        <div class="row row-court">',
		                '                            <div class="col-md-3 col-xs-4 text-right">',
		                '                                <span> 开庭地点：</span>',
		                '                            </div>',
		                '                            <div class="col-md-9 col-xs-8 text-left">',
		                '                                <span>' + (courtroomName?courtroomName:'未知') + '</span>',
		                '                            </div>',
		                '                        </div>',
		                '                        <div class="row row-court">',
		                '                            <div class="col-md-3 col-xs-4 text-right">',
		                '                                <span>开庭时间：</span>',
		                '                            </div>',
		                '                            <div class="col-md-9 col-xs-8 text-left">',
		                '                                <span>' + startDate + '</span>',
		                '                            </div>',
		                '                        </div>',
		                '                        <div class="row row-court">',
		                '                            <div class="col-md-3 col-xs-4 text-right">',
		                '                                <span>闭庭时间：</span>',
		                '                            </div>',
		                '                            <div class="col-md-9 col-xs-8 text-left">',
		                '                                <span>' + endDate + '</span>',
		                '                            </div>',
		                '                        </div>',
		                '                        <div class="row row-court">',
		                '                            <div class="col-md-3 col-xs-4 text-right">',
		                '                                <span> 庭审状态：</span>',
		                '                            </div>',
		                '                            <div class="col-md-3 col-xs-8 text-left">',
		                '                                <span>' + statusName + '</span>',
		                '                            </div>',
		                '                        </div>',
		                '                        <div class="row row-court">',
		                '                            <div class="col-md-3 col-xs-4 text-right">',
		                '                                <span>   基本案情：</span>',
		                '                            </div>',
		                '                            <div class="col-md-9 col-xs-8 text-left">',
		                '                                <span>' + caseDesc + '</span>',
		                '                            </div>',
		                '                        </div>',
		                '                    </div>'].join("");
		            $("#center-tab-1").html(""); 
		            $("#center-tab-1").append(html);
		            $("#judge_name").attr("href", r.base_path+"views/more_reviewing.html?judge="+judgeName);
//           			$("#secretary_name").attr("href", r.base_path + encodeURI("views/more_reviewing.html?secretary=" + secretaryName + "&city=" + now_video+'&court='+r.court_id));
		        }
		    });
		},
      	getCourtrecForId:function (planId) {
		    $.post(r.base_path + "courtrecForId", {planId: planId, courtId:r.court_id}, function (result) {
		        if (result && result.data) {
		        	 $("#center-tab-2").html(result.data[0]);
		             //绑定笔录下载地址--基于http下载
//		        	 $("#noteLoad").attr("href",result.data[1]);
		        }
		    });
		},
		getInfo:function(planId) {
		    $.ajax({
		        url: r.base_path + "playVideo",
		        type: 'post',
		        async: false,
		        dataType: "json",
		        data: {
		            planId: planId,
		            courtId:r.court_id
		        },
		        success: function (result) {
		        	console.info(result);
		            if (result.status == 0) {
		                if (!result.data ||result.data.length==0) {
		                    alert("没有找到点播信息！");
		                    return;
		                }
		                //result.data赋值给_data 以后操作_data
		                p._data = result.data;
		                var chn = "";
		                //构造点播通道select
						var video_row_1 = "";
	                    var video_row_2 = "";
	                    var count = 0 ;
		                $.each(p._data, function (i, n) {
		                    var filename = n.filename;
		                    var sxs = filename.match("(?=[^/]+$).+?(?=[_]+)");
		                    
		                    // console.log(sxs+n.chn);
		                    if (chn.indexOf("[" + n.chn + sxs + "]") == -1) {
		                    	if( count < 4 ){
		                    		video_row_1 += '<div class="col-md-3"><div class="group-left-dropdown" id="'+ n.channelsname +'">'
						                        +'        <a href="javascript:;" data-toggle="dropdown" class="btn btn-cmp-dropdown dropdown-toggle">'
						                        +'			<div class="'+ sxs + n.chn +'" >'+ n.channelsname+'<span class="caret"></span></div></a> '
						                        +'        	<ul class="dropdown-menu"> '
						                        +'        	</ul> '
						                        +'  </div></div>';  //onclick=get_video_channel(this)
		                    	}else{
		                    		video_row_2 += '<div class="col-md-3"><div class="group-left-dropdown" id="'+ n.channelsname +'">'
						                        +'        <a href="javascript:;" data-toggle="dropdown" class="btn btn-cmp-dropdown dropdown-toggle">'
						                        +'			<div class="'+ sxs + n.chn +'" >'+ n.channelsname+'<span class="caret"></span></div></a> '
						                        +'        	<ul class="dropdown-menu"> '
						                        +'        	</ul> '
						                        +'  </div></div>'; 
		                    	}
		                        chn += "[" + n.chn + sxs + "]";
		                        p.now_channel_arr.push(sxs + n.chn);
		                        count++;
		                    }
		                    
		                     var r = n.filename.match(/_\d+/g)[1].substr(1, 6);
                   			 n.time = r.substring(0, 2) + ":" + r.substring(2, 4);
		                });
	                 	$(".group-center-video-type").children("div:eq(0)").html("");
		                $(".group-center-video-type").children("div:eq(1)").html("");
		                $(".group-center-video-type").children("div:eq(0)").html(video_row_1);
		                $(".group-center-video-type").children("div:eq(1)").html(video_row_2);
		                initVideoSelect();
		                //初始化播放信道
		                if(p.now_channel_arr.length > 0){
		                	p.now_channel = p.now_channel_arr[0];
		                	get_video_channel(0);
		                }
		                
//		                //获取url的点播通道号进行选中点播通道的select，如果为空则初始化
//		                if (channel == null && $("#channels>option").length != 0) {
//		                    channel = 1;
//		                } else {
//		                    $("#channels>option").eq(channel).attr("selected", "selected");
//		                }
//		                //调用方法进行构造点播录像select
//		                initVideoSelect();
//		
//		                //尝试获取url中点播的视频编号进行选中点播录像select，如果为空则初始化
//		
//		                if (!videoNum) {
//		                    videoNum = 0;	//无录像
//		                }
//		                $("#videos>option:eq(" + parseInt(videoNum) + ")").attr("selected", "selected");
//		                //根据点播录像构造vlc的播放列表
//		                initPlayList();
//		
//		                //播放文件
//		                initdown(videoNum);
		
		            } else {
		                console.log(result.msg);
		            }
		        }
		    });
		},
        convert_data: function (data) {
            // console.log(typeof data,data);
            var res = [];
            $(data).each(function (index, elem) {
                res.push({
                    name: elem.courtName,
                    value: [parseFloat(elem.lng), parseFloat(elem.lat), elem.total, elem.courtId],
                    color: '#FF7F50',
                    itemStyle: {
                        normal: {
                            textStyle: {
                                fontSize: 16,
                                color: (elem.total > 100 ? '#FF7F50' : '#000')
                            }
                        },
                        emphasis: {
                            textStyle: {
                                color: (elem.total > 100 ? '#FF7F50' : '#000')
                            }
                        }
                    }
                });
            });
            // console.log(res);
            return res;
        }

    };
    init();
    //TODO 对外公开的方法写在这里
    window.p = {
        judge_change: Class.judge_change,
        courtroom_change: Class.courtroom_change,
        dept_change:Class.dept_change,
         _data:null,
        now_channel:null,//记录当前播放的信道
        now_channel_arr:[]
    };
}(window);

function page(now, totalPages, callback) {
    base.pagination('#_page', {
        currentPage: now,
        totalPages: totalPages,
        onPageClicked: function (page) {
            callback(page);
        }
    });
}
function page2(now, totalPages, callback) {
    base.pagination('#_page2', {
        currentPage: now,
        totalPages: totalPages,
        onPageClicked: function (page) {
            callback(page);
        }
    });
}

function get_video_channel(vlcItem){
	vlcItem = vlcItem ? vlcItem : 0;
//	var channel = $(val).attr('class');
//	if(!channel){
//		channel = val;
//	}
//	console.info(channel);
//	if(channel == p.now_channel){
//		return;
//	}else{
//		p.now_channel = channel;
		var vlc = getVLC("vlc");
	    if (vlc) {
	        //一言不合先清除下播放列表
	        vlc.playlist.items.clear();
	        //防止出现意外时初始化视频号
	        $.each(p._data, function (i, n) {
	        	var options = [":vout-filter=deinterlace", ":deinterlace-mode=linear"];
	            var filename = n.filename;
	            var sxs = filename.match("(?=[^/]+$).+?(?=[_]+)");
	           
	            var temp = p.now_channel;
	//              console.log(sxs+n.chn + channel,"----sxs",sxs+n.chn,"----temp",temp);
	            if (sxs + n.chn == temp) {
	                vlc.playlist.add("http://" + n.url + ":8200/" + n.filename, "", options);
//	            	vlc.playlist.add("http://localhost:8080/" + n.filename, "", options);
	            	options = [];
	            }
	        });
	        vlc.playlist.playItem(vlcItem);
	    }
//	}
}

function initVideoSelect() {
    $.each(p._data, function (j, n) {
    	var filename = n.filename;
        var sxs = filename.match("(?=[^/]+$).+?(?=[_]+)");
    	var now_name = n.channelsname;
    	var temp_channel = sxs + n.chn;
    	if(j < p._data.length-1 ){
    		if(now_name == p._data[j+1].channelsname){
	    		 $("#"+n.channelsname).find("ul").append('<li><a href="javascript:;" class="'+temp_channel+'" onclick="select_video_channel(this)">' + n.time+'--'+p._data[j+1].time +'</a></li>');
	    	}else{
	    		 $("#"+n.channelsname).find("ul").append('<li><a href="javascript:;" class="'+temp_channel+'" onclick="select_video_channel(this)">' + n.time +'</a></li>');
	    	}
    	}else{
    		$("#"+n.channelsname).find("ul").append('<li><a href="javascript:;" class="'+temp_channel+'" onclick="select_video_channel(this)">' + n.time +'</a></li>');
    	}
    });
}
function select_video_channel(val){
	p.now_channel = $(val).attr("class");
	var vlcItem = $(val).parents("li").parents("ul").find("li").index($(val).parents("li"));
//	console.info(p.now_channel,"   ",vlcItem);
	get_video_channel(vlcItem);
}

function currentServerIP() {
    var ip = '';
    $.ajax({
        url: r.base_path + "currentServerIP",
        type: 'post',
        async: false,
        dataType: "text",
        success: function (result) {
            ip = result;
        }
    });
    return ip;
}

function getCgf(uid, cid, courtIp,channel) {
    channel = channel?channel:1;
    $(".group-center-video-type").children("div:eq(0)").html("");
    $(".group-center-video-type").children("div:eq(1)").html("");
    $.ajax({
        url: r.base_path + "sys/courtSetting/getCfgInfo",
        type: "post",
        dataType: "json",
        data: {
            cId: cid,
            index: channel,
            ip: courtIp
        },
        success: function (result) {
            if (result != null) {
                var data = result.data;
                var count = 0;
                var video_row_1 = "";
                var video_row_2 = "";
                
                for (var key in  data) {
                    if( count < 4 ){
                		video_row_1 += '<div class="col-md-3"><div>'+key+'</div></div>';  //onclick=get_video_channel(this)
                	}else{
                		video_row_2 += '<div class="col-md-3"><div>'+key+'</div></div>';
                	}
                    count = count + 1;
                }
                $(".group-center-video-type").children("div:eq(0)").html(video_row_1);
                $(".group-center-video-type").children("div:eq(1)").html(video_row_2);
                //初始化直播信号
                $(".group-center-video-type").find(".col-md-3").eq(channel - 1).find("div").attr("class","active");
                var d = $(".group-center-video-type").find(".col-md-3").eq(channel - 1).find("div").html();
                var cha = data[d];//默认显示
                initialise(courtIp, cha);
                 console.log(data,d,cha);
                $(".group-center-video-type").children("div").children('div').click(function () {
                    var inx = $(".group-center-video-type").find(".col-md-3").index(this) + 1;
                    console.info(inx);
                    getCgf(uid, cid, courtIp,inx);
                });
            }

        },
        error: function () {
        }
    });
}

function initialise(courtIp, cfg) {
    var vlc = getVLC("vlc");
    if (vlc) {
        vlc.playlist.items.clear();
        while (vlc.playlist.items.count > 0) {
            // clear() may return before the playlist has actually been cleared
            // just wait for it to finish its job
        }
        var options = [":rtsp-tcp"];
        var itemId;
        console.log("rtsp://" + courtIp + "/" + cfg);
        itemId = vlc.playlist.add("rtsp://" + courtIp + "/" + cfg, "", options);
        
        if (itemId != -1) {
            vlc.playlist.playItem(itemId);
        }else {
            alert("cannot play at the moment !");
        }
    }
}
